package algorithm.view.prepare;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


/**
 * @author bingo
 * @Description 移动鼠标更改背景
 * @Date 2018/7/20
 */
public class Demo3 {
    public static void main(String[] args) {
        Frame f = new Frame();
        f.setSize(400,400);
        f.setVisible(true);
        f.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        f.setLayout(new FlowLayout());
        Button button1 = new Button("青色");
        Button button2 = new Button("蓝色");
        Button button3 = new Button("粉色");


        f.add(button1);
        f.add(button2);
        f.add(button3);
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e){
                f.setBackground(Color.cyan);
            }
        });

        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e){
                f.setBackground(Color.blue);
            }
        });

        button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e){

                f.setBackground(Color.pink);
            }
        });
    }
}
